// License: http://www.codeplex.com/entlibcontrib/Project/License.aspx
// Author: Randy

using System;
using System.Globalization;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging.Filters;
using Microsoft.Practices.EnterpriseLibrary.Logging.Instrumentation;
using EntLibContrib.Logging.Parser;

#if !NUNIT
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
#endif

namespace EntLibContrib.Logging.UnitTests.Parser
{
    [TestClass]
    public class LoggingExceptionTests
    {
        private const string configurationFilepath = @"Parser\LoggingExceptionTests.config";

        [TestMethod, ExpectedException(typeof(LoggingCategoryNotDefinedException))]
        public void TestCategoryNotFound()
        {
            LogReaderTest("CategoryNotFound");
        }
        [TestMethod, ExpectedException(typeof(LoggingFileTraceListenerNotFoundException))]
        public void TestFileTraceListenerNotFound()
        {
            LogReaderTest("General");
        }
        [TestMethod, ExpectedException(typeof(LoggingFormatterNotDefinedException))]
        public void TestFormatterNotDefined()
        {
            LogReaderTest("FormatterNotDefined");
        }
        [TestMethod, ExpectedException(typeof(LoggingTextFormatterNotFoundException))]
        public void TestTextFormatterNotFound()
        {
            LogReaderTest("TextFormatterNotFound");
        }
        [TestMethod, ExpectedException(typeof(System.ArgumentException))]
        public void TestFileNameNotDefined()
        {
            LogReaderTest("FileNameNotDefined");
        }
        public void LogReaderTest(string categoryName)
        {
            foreach (LogEntry readLogEntry in new CategoryLogFileReader().ParseLogFile(configurationFilepath, categoryName, null, null))
            {
            }
        }

        [TestMethod, ExpectedException(typeof(LoggingSectionNotDefinedException))]
        public void TestSectionNotDefined()
        {
            foreach (LogEntry readLogEntry in new CategoryLogFileReader().ParseLogFile(@"Parser\TestLogReaderSectionNotDefined.config", "General", null, null))
            {
            }
        }
        [TestMethod, ExpectedException(typeof(LoggingSectionNotDefinedException))]
        public void TestAppCatagoryNames()
        {
            foreach (string categoryName in CategoryLogFileReader.AppCatagoryNames())
            {
                string logFileName = CategoryLogFileReader.GetConfigTraceListenerFileName(categoryName);
            }
        }
    }
}
